package com.itheima.common;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * 通用返回结果，服务端响应的数据最终都会封装成此对象
 *
 * @param <T>
 */
public class JsonResult<T> implements Serializable {

    private Integer code; //编码：1成功，0和其它数字为失败

    private String msg; //错误信息

    private T data; //数据

   private Map map = new HashMap(); //动态数据

    private Throwable cause;

    public static <T> JsonResult<T> success(String msg) {
        JsonResult<T> jsonResult = new JsonResult<T>();
        jsonResult.msg = msg;
        jsonResult.code = 1;
        return jsonResult;
    }

    public static <T> JsonResult<T> select(T object ,String msg) {
        JsonResult<T> jsonResult = new JsonResult<T>();
        jsonResult.msg = msg;
        jsonResult.data = object;
        jsonResult.code = 1;
        return jsonResult;
    }


    public static <T> JsonResult<T> imgSuccess(T object ,String msg) {
        JsonResult<T> jsonResult = new JsonResult<T>();
        jsonResult.msg = msg;
        jsonResult.data = object;
        jsonResult.code = 1;
        return jsonResult;
    }

    public static <T> JsonResult<T> loginSuccess(T object ,String msg) {
        JsonResult<T> jsonResult = new JsonResult<T>();
        jsonResult.msg = msg;
        jsonResult.data = object;
        jsonResult.code = 1;
        return jsonResult;
    }

    public static <T> JsonResult<T> error(String msg) {
        JsonResult<T> jsonResult = new JsonResult<T>();
        jsonResult.msg = msg;
        jsonResult.code = 0;
        return jsonResult;
    }

    public static <T> JsonResult<T> exception(Integer code,T object,String msg) {
        JsonResult<T> jsonResult = new JsonResult<T>();
        jsonResult.data = object;
        jsonResult.msg = msg;
        jsonResult.code =code ;
        return jsonResult;
    }


    public static <T> JsonResult<T> employeePaginationSuccess (T object ,String msg) {
        JsonResult<T> jsonResult = new JsonResult<T>();
        jsonResult.msg = msg;
        jsonResult.data = object;
        jsonResult.code = 1;
        return jsonResult;
    }

    public static <T> JsonResult<T> employeePaginationError (T object ,String msg) {
        JsonResult<T> jsonResult = new JsonResult<T>();
        jsonResult.msg = msg;
        jsonResult.data = object;
        jsonResult.code = 0;
        return jsonResult;
    }
    public static <T> JsonResult<T> orderPagingErroe (T object) {
        JsonResult<T> jsonResult = new JsonResult<T>();
        jsonResult.data = object;
        jsonResult.code = 0;
        return jsonResult;
    }


    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

   public Map getMap() {
       return map;
   }

   public void setMap(Map map) {
       this.map = map;
   }
}
